﻿@Cofe ?= {}

$ = jQuery
utils = Cofe.utils

onRefreshing = (entryItemList, entryList) ->
     entryItemList.el.waypoint('disable')
     #console.log("refreshing")

onRefreshed = (entryItemList, entryList) ->
     entryItemList.el.waypoint('enable')
     $.waypoints('refresh');
     #console.log("refreshed")

waypointSupport = 
  initWaypoint : (entryItemList) ->
     @el.waypoint(
        () => 
           #console.log("waypoint")
           #console.log(@entryList.currentPage)
           if (@hasNextPage())
             utils.notify(undefined, "Loading page " + (entryItemList.entryList.currentPage + 1))
             @addNextPage()
        ,
        { offset : 'bottom-in-view', enabled: false }
     )
     entryItemList.bind("refreshing", onRefreshing)
     entryItemList.bind("refreshed", onRefreshed)

Cofe.waypointSupport = waypointSupport